]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
st: Add StClipboard method to set arbitrary clipboard content
authorCarlos Garnacho <carlosg@gnome.org>
Tue, 5 Nov 2019 23:40:17 +0000 (00:40 +0100)
committerFlorian Müllner <florian.muellner@gmail.com>
Wed, 6 Nov 2019 22:45:22 +0000 (22:45 +0000)
This complements the current text-based API.

https://gitlab.gnome.org/GNOME/mutter/issues/789
https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/810

src/st/st-clipboard.c
src/st/st-clipboard.h

index b2d8e7f940b10b1171277952b5f023b6e0a2a7a8..1dcd1e75f381c1a13113ebfce0d31562c3c83a87 100644 (file)
@@ -194,6 +194,36 @@ st_clipboard_get_text (StClipboard            *clipboard,
                                  data);
 }
 
+/**
+ * st_clipboard_set_content:
+ * @clipboard: A #StClipboard
+ * @type: The type of clipboard that you want to set
+ * @mimetype: content mimetype
+ * @bytes: content data
+ *
+ * Sets the clipboard content.
+ **/
+void
+st_clipboard_set_content (StClipboard     *clipboard,
+                          StClipboardType  type,
+                          const gchar     *mimetype,
+                          GBytes          *bytes)
+{
+  MetaSelectionType selection_type;
+  MetaSelectionSource *source;
+
+  g_return_if_fail (ST_IS_CLIPBOARD (clipboard));
+  g_return_if_fail (meta_selection != NULL);
+  g_return_if_fail (bytes != NULL);
+
+  if (!convert_type (type, &selection_type))
+    return;
+
+  source = meta_selection_source_memory_new (mimetype, bytes);
+  meta_selection_set_owner (meta_selection, selection_type, source);
+  g_object_unref (source);
+}
+
 /**
  * st_clipboard_set_text:
  * @clipboard: A #StClipboard
@@ -207,22 +237,15 @@ st_clipboard_set_text (StClipboard     *clipboard,
                        StClipboardType  type,
                        const gchar     *text)
 {
-  MetaSelectionType selection_type;
-  MetaSelectionSource *source;
   GBytes *bytes;
 
   g_return_if_fail (ST_IS_CLIPBOARD (clipboard));
   g_return_if_fail (meta_selection != NULL);
   g_return_if_fail (text != NULL);
 
-  if (!convert_type (type, &selection_type))
-    return;
-
   bytes = g_bytes_new_take (g_strdup (text), strlen (text));
-  source = meta_selection_source_memory_new ("text/plain;charset=utf-8", bytes);
+  st_clipboard_set_content (clipboard, type, "text/plain;charset=utf-8", bytes);
   g_bytes_unref (bytes);
-
-  meta_selection_set_owner (meta_selection, selection_type, source);
 }
 
 void
index 86e67e1eeb197b2be3d6877ac1b8aaf98746400b..60e3846010c4e80d684a913cd663112543d49fc6 100644 (file)
@@ -73,6 +73,11 @@ void st_clipboard_set_text (StClipboard             *clipboard,
                             StClipboardType          type,
                             const gchar             *text);
 
+void st_clipboard_set_content (StClipboard          *clipboard,
+                               StClipboardType       type,
+                               const gchar          *mimetype,
+                               GBytes               *bytes);
+
 void st_clipboard_set_selection (MetaSelection *selection);
 
 G_END_DECLS